var commonFunc ={};
var constants ={
    localCurl : "http://localhost:8090/chatroom",
    styleSize:'small'
}


commonFunc.submit=function(url,submitType, parameter, fnSuccess, fnError,contentType, Async){
    //判断是否需要同步ajax
    if (typeof (Async) == "undefined") {
        Async = true;
    };
    if(contentType == "obj"){
        parameter = JSON.stringify(parameter);
        contentType = "application/json; charset=utf-8";
    }else if(contentType == "upload"){
        //contentType = "application/x-www-form-urlencoded;charset=UTF-8";
    }else {
        contentType = "application/x-www-form-urlencoded;charset=UTF-8";
    }
    url = constants.localCurl+url;
    $.ajax({
        type: submitType,
        data: parameter,
        dataType: 'json',
        contentType:contentType,
        url: url,
        cache:false,
        beforeSend: function(XMLHttpRequest) {

        },
        crossDomain: true == !(document.all),
        xhrFields: {
            withCredentials: true
        },
        async: Async,
        success: function(data) {
            //服务器返回响应，根据响应结果，分析是否登录成功；
            var code=data.code+"";
            if (code == 1000) {
                return;
            } else if(code=="0"){
                fnSuccess(data);
            }else{
                fnError(data);
            }
        },
        complete: function (data) {
        },
        error: function (xhr, type, errorThrown) {
            //异常处理；
            fnError(xhr, type, errorThrown);
            console.log(xhr);
            console.log(type);
            console.log(JSON.stringify(errorThrown));
        }
    });
}
